var MiniIcons =
[
	"Tornade",

"Orage Tropical",

"Ouragan",

"Orages",

"Orages",

"Pluie et Neige",

"Pluie et Verglas",

"Neige et Verglas",

"Brouillard VerglaÃ§ant",

"Brouillard",

"Pluie VerglaÃ§ante",

"Averses",

"Averses",

"Bourrasques de neige",

"Petites chutes de neige",

"Chutes de neige - Vent",

"Neige",

"grÃªle",

"Verglas",

"Non communiquÃ©",

"brumeux",

"Brume",

"Non communiquÃ©",

"Non communiquÃ©",

"Vent",

"Froid",

"Nuageux",

"Passages nuageux",

"Passages nuageux",

"Passages nuageux",

"Passages nuageux",

"Ciel Clair",

"EnsoleillÃ©",

"Clair",

"Beau Temps",

"Pluie et GrÃªle mÃ©langÃ©es",

"TrÃ¨s Chaud",

"Passages nuageux avec orages",

"Orage et Ã©claircies",

"Orage et Ã©claircies",

"Pluies et Ã©claircies",

"Chute de neige importante",

"Petite chutes de neige",

"Chute de neige importante",

"Partiellement couvert",

"Tonnerre",

"Chutes de neige",

"Tonnerre et Ã©claircies",

"Pas d'info",

];


function constructError (string)
{
	return {error:true, errorString:string};
}

function findChild (element, nodeName)
{
	var child;
	
	for (child = element.firstChild; child != null; child = child.nextSibling)
	{
		if (child.nodeName == nodeName)
			return child;
	}
	
	return null;
}


function fetchWeatherData (callback, zip)
{
	url="http://weather.yahooapis.com/forecastrss?u=f&p=" //u=Farenheit, because accuWeather sucks
	
	var xml_request = new XMLHttpRequest();
	xml_request.onload = function(e) {xml_loaded(e, xml_request, callback);}
	xml_request.overrideMimeType("text/xml");
	xml_request.open("GET", url+zip);
	xml_request.setRequestHeader("Cache-Control", "no-cache");
	xml_request.send(null);	
	
	return xml_request;
}

function xml_loaded (event, request, callback)
{
	if (request.responseXML)
	{
	 	var obj = {error:false, errorString:null};
		var effectiveRoot = findChild(findChild(request.responseXML, "rss"), "channel");
		obj.city = findChild(effectiveRoot, "yweather:location").getAttribute("city");
		obj.realFeel = findChild(effectiveRoot, "yweather:wind").getAttribute("chill");//Only accounts for windChill
		
		conditionTag = findChild(findChild(effectiveRoot, "item"), "yweather:condition");
		obj.temp = conditionTag.getAttribute("temp");
		obj.icon = conditionTag.getAttribute("code");
		obj.description = conditionTag.getAttribute("text"); 
		callback (obj); 
	}else{
		callback ({error:true, errorString:"XML request failed. no responseXML"});
	}
}


function validateWeatherLocation (location, callback)
{
	var obj = {error:false, errorString:null, cities: new Array};
	obj.cities[0] = {zip: location}; //Not very clever, are we?
	callback (obj);
}